﻿using System.Windows.Forms;

namespace UsercontrolDatalinkage
{
    public partial class ControlPanel : Form
    {
        private IData dataSource;

        public ControlPanel()
        {
            InitializeComponent();
        }

        public ControlPanel(IData dataSource)
        {
            InitializeComponent();
            this.dataSource = dataSource;
            SetPV(dataSource.PV);
            SetMV(dataSource.MV);
        }

        private void txt_mv_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                int mvVal;
                if (int.TryParse(txt_mv.Text, out mvVal))
                {
                    dataSource.MV = mvVal;
                }
                else
                {
                    MessageBox.Show("请输入整数", "提示");
                    txt_mv.Text = "";
                }
            }
        }

        public void SetPV(int pv)
        {
            txt_pv.Text = pv.ToString();
        }

        public void SetMV(int mv)
        {
            txt_mv.Text = mv.ToString();
        }
    }
}
